﻿using Charades.Web.VkAuthentication;
using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.Facebook;
using Microsoft.Owin.Security.OAuth;
using Owin;

namespace Charades.Web
{
	public partial class Startup
	{
		// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
		public void ConfigureAuth(IAppBuilder app)
		{
			// Enable the application to use a cookie to store information for the signed in user
			app.UseCookieAuthentication(new CookieAuthenticationOptions
			{
				AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
				LoginPath = new PathString("/login")
			});
			// Use a cookie to temporarily store information about a user logging in with a third party login provider
			app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

			// Uncomment the following lines to enable logging in with third party login providers
			//app.UseMicrosoftAccountAuthentication(
			//    clientId: "",
			//    clientSecret: "");

			app.UseVkontakteAuthentication(
				appId: ServerSettings.VkAppId,
				appSecret: ServerSettings.VkAppSecret,
				scope: "email");

			app.UseTwitterAuthentication(
			   consumerKey: ServerSettings.TwitterConsumerKey,
			   consumerSecret: ServerSettings.TwitterConsumerSecret);

			var facebookAuthenticationOptions =
				new FacebookAuthenticationOptions()
					{
						AppId = ServerSettings.FacebookAppId,
						AppSecret = ServerSettings.FacebookAppSecret
					};
			facebookAuthenticationOptions.Scope.Add("email");

			app.UseFacebookAuthentication(facebookAuthenticationOptions);

			app.UseGoogleAuthentication(
				clientId: ServerSettings.GoogleClientId,
				clientSecret: ServerSettings.GoogleClientSecret);
		}
	}
}